﻿// 一共有k名同学,第1名同学从1开始报数
// 下一名同学报数 (x+t) mod M
// 如果报的数含1,则称为I类数字
// 如果报的数含0,则称为II类数字
// 从文件game.in中读取三个正整数 k t M
// 考试过程中补充说明:
//   结果输出仅属于I类数字的个数,仅属于II类数字的个数,以及两类数字都包含的个数
//   即输出结果中I类和II类要扣除III类

#include <iostream>
#include <fstream>

void game_report_number(uint64_t k, uint64_t t, uint64_t M, std::ostream& output);
uint64_t report_next(uint64_t x, uint64_t t, uint64_t M);
bool check_contains(uint64_t x, int d);

int main()
{
	uint64_t k, t, M;
#ifdef MY_NOI
	std::ifstream fin("game.in");
	std::ofstream fout("game.out");

	std::istream &xInput = fin;
	std::ostream &xOutput = fout;
#else
	std::istream &xInput = std::cin;
	std::ostream &xOutput = std::cout;
#endif

	while (!xInput.eof()) {
		xInput >> k >> t >> M;

		game_report_number(k, t, M, xOutput);

		// skip blank lines
		while (xInput.peek() == '\n') {
			xInput.get();
		}
	}

	return 0;
}

void game_report_number(uint64_t k, uint64_t t, uint64_t M, std::ostream& output)
{
	unsigned int countI = 0, countII = 0, countBoth=0;
	uint64_t next = 1; // 第一个同学报数为1

	for (int i = 0; i < k; i++) {
		// std::cout << next << "\n";
		bool bI = check_contains(next, 1);
		bool bII = check_contains(next, 0);

		if (bI)  countI++;
		if (bII) countII++;
		if (bI && bII) countBoth++;

		next = report_next(next, t, M);
	}

	// std::cout << countI - countBoth << " " << countII - countBoth << " " << countBoth << std::endl;
	output << countI-countBoth << " " << countII-countBoth << " " << countBoth << std::endl;
}

uint64_t report_next(uint64_t x, uint64_t t, uint64_t M)
{
	return (x + t) % M;
}

bool check_contains(uint64_t x, int d)
{
	while (x > 0) {
		if (x % 10 == d) {
			return true;
		}
		x /= 10;
	}
	return false;
}